//-----------------------------------------------------
// entity.h
//-----------------------------------------------------

/**
 * @file entity.h
 */

#pragma once

#include "tools/vector.h"
#include <list>



namespace logic {
	


	class CEntity {

	public:
		class Observer;
	
	private:
		tools::CVector _pos;
		bool _visible;
		std::list<Observer*> _observers;

	public:

		CEntity();
		virtual ~CEntity();

		/*****************************/
		/*		ENTITY OBSERVER      */
		/*****************************/

		/**
		 * Each logic entity has an associated graphic entity that implements this interface.
		 * Any time the logic entity calls a method that implies the modification of it's graphic
		 * representation, it will notify that graphic representation through this observer.
		 */

	public:
		class Observer {

		public:

			virtual void positionChanged(const CEntity *entity, const tools::CVector &pos) = 0;
			virtual void visibilityChanged(const CEntity *entity, bool visibility) = 0;

		}; // class Observer
		
		/*****************************/
		/*		ENTITY METHODS       */
		/*****************************/

		virtual void update();
		bool addObserver(Observer *newObserver);
		bool removeObserver(Observer *oldObserver);

		void setVisible(bool visible)
		{
			_visible = visible;
			emitVisibilityChanged();
		}

		tools::CVector getPosition() const { return _pos; }
		bool isVisible() const { return _visible; }

		virtual void setPosition(const tools::CVector &newPos)
		{
			_pos = newPos;
			emitPositionChanged();
		}

	private:

		void emitPositionChanged();
		void emitVisibilityChanged();

	}; // class CEntity


} // namespace logic